|
In software, a stack overflow occurs if the call stack pointer exceeds the stack bound. The call stack may consist of a limited amount of address space, often determined at the start of the program. The size of the call stack depends on many factors, including the programming language, machine architecture, multi-threading, and amount of available memory. When a program attempts to use more space than is available on the call stack (that is, when it attempts to access memory beyond the call stack's bounds, which is essentially a buffer overflow), the stack is said to ''overflow'', typically resulting in a program crash. ==Infinite recursion== (詳細はWhat is the difference between a segmentation fault and a stack overflow? ) at StackOverflow〕 An example of infinite recursion in C. The function ''foo'', when it is invoked, continues to invoke itself, allocating additional space on the stack each time, until the stack overflows resulting in a segmentation fault.〔 However, some compilers implement tail-call optimization, allowing infinite recursion of a specific sort—tail recursion—to occur without stack overflow. This works because tail-recursion calls do not take up additional stack space.〔(【引用サイトリンク】 url=http://www.federated.com/~jim/schintro-v14/schintro_73.html )〕 C compiler options will effectively enable tail-call optimization; compiling the above simple program using gcc with -O1 will result in a segmentation fault, but not when using -O2 or -O3 , since these optimization levels imply the -foptimize-sibling-calls compiler option. Other languages, such as Scheme, require all implementations to include tail-recursion as part of the language standard.抄文引用元・出典: フリー百科事典『 ウィキペディア(Wikipedia)』 ■ウィキペディアで「Stack overflow」の詳細全文を読む スポンサード リンク
|